/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GameLogic;

import Algorithm.KDTree;
import Algorithm.Pathfinding;
import java.util.ArrayList;
import java.util.Map.Entry;
import java.util.TreeSet;

/**
 *
 * @author Ix
 */

public class MobAura implements Comparable<MobAura>
{
    public final static double MAX_RANGE = 10;
    public double Range;
    public String name;
    public Buff b;
    
    public MobAura(String name, double range, Buff b)
    {
        this.b = b;
        this.name = name;
        this.Range = range;
    }
    
    @Override
    public int compareTo(MobAura m) {
        return name.compareTo(m.name);
    }
    @Override
    public boolean equals(Object m) {
        if(m.getClass() != MobAura.class)
            return false;
        return name.equals(((MobAura)m).name);
    }
    @Override
    public int hashCode() {
        return name.hashCode();
    }
    
    public static void UpdateAuras(Mob m, KDTree k)
    {
        
        ArrayList<Tower> tList = k.GetNearbyTowers(m.GetPosition(), MAX_RANGE);
        TreeSet<Buff> oAuras = new TreeSet<Buff>();
        for(Entry<Buff, Integer> e : m.Buffs.entrySet())
            if(e.getValue() == Buff.AURA)
                oAuras.add(e.getKey());
        if(tList != null && tList.size() > 0)
        {
        for(Tower t : tList)
        {
            if(t.type.mAura != null && 
               Pathfinding.GetDist2(m.GetPosition(), t.getCenter()) <= t.type.mAura.Range * t.type.mAura.Range)
            {
                oAuras.remove(t.type.mAura.b);
                t.type.mAura.b.Apply(m);
            }
        }
        }
        for(Buff b : oAuras)
            b.Remove(m);
    }
}
